package com.xbongbong.paas.help.symbol;

import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.util.ItemUtil;

import java.util.Objects;

/**
 * 文本格式进行校验
 * 下拉框单选、单选按钮
 * @author 吴峰
 * @date 2021/01/07 14:32
 */
public class ComboSymbolHandle extends TextSymbolHandle {



    @Override
    public boolean like(Object target, PaasFormDataEntity source, FieldAttrEntity fieldAttrEntity) throws XbbException {

        Object object = ItemUtil.getCustomItemList(fieldAttrEntity, source.getData());
        return Objects.nonNull(object) && object.toString().contains(target.toString());
    }

    @Override
    public boolean noLike(Object target, PaasFormDataEntity source, FieldAttrEntity fieldAttrEntity) throws XbbException {
        Object object = ItemUtil.getCustomItemList(fieldAttrEntity, source.getData());
        return Objects.isNull(object) || !object.toString().contains(target.toString());
    }

    @Override
    public boolean in(Object target, PaasFormDataEntity source, FieldAttrEntity fieldAttrEntity) throws XbbException {
        return in(target, source.getData().get(fieldAttrEntity.getAttr()));
    }
}
